package com.info33.platform.doc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.doc.dto.DocFileDirectoryDTO;
import com.info33.platform.doc.entity.DocFileDirectory;
import com.info33.platform.doc.service.DocFileDirectoryService;
import com.info33.platform.doc.vo.DocFileDirectoryVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author admin
 */
@RestController
@RequestMapping("/DocFileDirectory")
@Api(tags = "文档管理 - 数据仓库 - 分组目录")
public class DocFileDirectoryController extends BaseController<DocFileDirectoryService, DocFileDirectory> {

    private final DocFileDirectoryService docFileDirectoryService;

    @Autowired
    public DocFileDirectoryController(DocFileDirectoryService docFileDirectoryService) {
        super(docFileDirectoryService);
        this.docFileDirectoryService = docFileDirectoryService;
    }
    
    @GetMapping(value = "/getDirectoryTree/{type}")
    @ApiOperation(value = "获取目录树")
    public Result<List<DocFileDirectoryVO>> getDirectoryTree(@PathVariable String type) {
        return Result.ok(docFileDirectoryService.getDirectoryTree(getCurrentUser(), type));
    }
    
    @PostMapping("/saveFileDirectory")
    @ApiOperation(value = "新增目录")
    public Result<?> saveFileDirectory(@RequestBody DocFileDirectoryDTO docFileDirectoryDTO) {
        return docFileDirectoryService.saveFileDirectory(getCurrentUser(), docFileDirectoryDTO);
    }
    
    @PostMapping("/editFileDirectory")
    @ApiOperation(value = "编辑目录")
    public Result<?> editFileDirectory(@RequestBody DocFileDirectoryDTO docFileDirectoryDTO) {
        return docFileDirectoryService.editFileDirectory(getCurrentUser(), docFileDirectoryDTO);
    }
    
    @GetMapping("/removeFileDirectory/{id}")
    @ApiOperation(value = "删除目录")
    public Result<?> removeFileDirectory(@PathVariable Long id) {
        return docFileDirectoryService.removeFileDirectory(getCurrentUser(), id);
    }

}